/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.dominatingspecies.frontend.element;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.wicket.markup.html.form.ListMultipleChoice;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import pa165.dominating.species.enums.ElementType;
import pa165.dominating.species.tos.ElementTo;
import pa165.dominatingspecies.service.impl.ElementServiceImpl;

/**
 *
 * @author Ondrej Prazak
 */
public class EnumListMultiple<T extends Enum<T>> extends ListMultipleChoice<T> {

    @SpringBean(name = "elementService")
    private ElementServiceImpl elementService;

    public EnumListMultiple(String id, IModel<Collection<T>> model) {
        super(id);
        setModel(model);
        setChoiceRenderer(new EnumChoiceRenderer(this));
    }

    public EnumListMultiple(String id, IModel<Collection<T>> model, EnumChoiceRenderer<T> choiceRenderer) {
        super(id);
        setModel(model);
        setChoiceRenderer(choiceRenderer);
    }

    @Override
    public List getChoices() {
        List<ElementTo> found = elementService.getAllElementTos();
        List<ElementType> types = new ArrayList<>();
        for (ElementTo to : found) {
            types.add(to.getType());
        }
        return types;
    }
}
